<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ page import="com.yaodian100.core.common.utils.ServerValue"%>
<%@ include file="/taglibs.jsp"%>
<s:url value="/images" var="imgPath"/>
<script type="text/javascript" charset="UTF-8" src="/js/formValidator.js" charset="UTF-8"></script>
<script type="text/javascript" charset="UTF-8" src="/js/formValidatorRegex.js" charset="UTF-8"></script>
<!-- 月历 -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick-zh-CN.js"></script>
<!-- 時間 -->	
<script type="text/javascript" src="/js/jquery.timePicker.js"></script>
<link rel="stylesheet" type="text/css" href="/js/timePicker.css"/>
<script type="text/javascript" charset="UTF-8" src="/css/jquery-ui-1.7.2.custom.min.js"></script>
<link rel="stylesheet" type="text/css" href="/css/jquery-ui-1.7.2.custom.css"/>
<link rel="stylesheet" type="text/css" href="/css/smoothness.datepick.css" />
<script language="javascript">
	$().ready( function() {
		$('#startDate').datepick({minDate: null, showOn: 'both', 
	    	buttonImageOnly: true, buttonImage: '${imgPath}/calendar.gif',numberOfMonths:2,dateFormat:"yy-mm-dd",yearRange: '-50:+50'});
		$('#endDate').datepick({minDate:new Date(), showOn: 'both', 
	    	buttonImageOnly: true, buttonImage: '${imgPath}/calendar.gif',numberOfMonths:2,beforeShow:customRange,dateFormat:"yy-mm-dd",yearRange: '-50:+50'});
		function customRange (){
			var startDt = $('#startDate').val(); //起始日
			var endDt = new Date(parseInt(startDt.substring(0,4),10),parseInt(startDt.substring(5,7),10)-1,parseInt(startDt.substring(8,10),10)); //結束日
			return {minDate:endDt}; 
		}
		$("#startTime").timePicker();
		$("#endTime").timePicker();
		$.formValidator.initConfig({formid:"formObj",onerror:function(msg){alert(msg)},onsuccess:function(){document.forms[0].action='save.do';return true;}});

		//栏位资料验证
		$("#campaignName").formValidator().inputValidator({	
			min:1,
			max:45,
			onerror:"活动名称须小于45个字元且为必填" });
		$("#startDate").formValidator().inputValidator({
			min:10,
			max:10,
			onerror:"起始时间不能为空值,且格式为yyyy-MM-dd" }).compareValidator({
			desid:"endDate",
			operateor:"<",
			onerror:"结束时间必须晚于起始"});
		$("#endDate").formValidator().inputValidator({	
			forcevalid:true,	
			min:10,
			max:10,
			onerror:"结束时间不能为空值,且格式为yyyy-MM-dd" });
		<c:if test="${campaign.type == 'M01' || campaign.type == 'M04'}">
		$("#startPeriod").formValidator().inputValidator({
			min:1,
			max:999,
			onerror:"请填写效期开始日"
		});
		$("#periodDays").formValidator().inputValidator({
			min:1,
			max:999,
			onerror:"请填写效期长度"
		});

		$("input:[id*='upperLimit_']").click(function(){
			var text = $(this).attr('id').split('_')[1];
			if($(this).attr('checked')){
				$("#bonusLimit_"+text).val('');
				$("#span_bonusLimit_"+text).show();
				$("#bonusLimit_"+text).formValidator().inputValidator({
					min:1,
					max:99999999,
					onerror:"请填写积分发送封顶上限"
				});
			}else{
				$("#bonusLimit_"+text).val('-1');
				$("#bonusLimit_"+text).formValidator().inputValidator({});
				$("#span_bonusLimit_"+text).hide();
			}
		});
		$("input:checked[id*='upperLimit_']").each(function(){
			var text = $(this).attr('id').split('_')[1];
			$("#bonusLimit_"+text).formValidator().inputValidator({
				min:1,
				max:99999999,
				onerror:"请填写积分发送封顶上限"
			});
		});
		</c:if>
		<c:if test="${campaign.type == 'M02'}">
		$("#offsetRate").formValidator().inputValidator({
			min:1,
			max:99999,
			onerror:"请填写积分折抵比率"
		});
		$("#offsetUpperLimit").formValidator().inputValidator({
			min:1,
			max:99,
			onerror:"请填写积分折抵上限"
		});
		$("#offsetDiscountLimit").formValidator().inputValidator({
			min:1,
			max:99999,
			onerror:"请填写积分折抵金额上限"
		});
		</c:if>
		<c:if test="${campaign.type == 'M03'}">
		$("#loginCount").formValidator().inputValidator({
			min:1,
			max:99,
			onerror:"请填写登入次数"
		});
		$("#giveBonus").formValidator().inputValidator({
			min:1,
			max:999,
			onerror:"请填写发送积分"
		});
		</c:if>

		<c:if test="${campaign.type == 'M04'}">
		$("#commentFirst3").formValidator().inputValidator({
			min:1,
			max:9999,
			onerror:"请填写前三名评论送积分数"
		});
		$("#commentOthers").formValidator().inputValidator({
			min:1,
			max:9999,
			onerror:"请填写其他评论送机分数"
		});
		</c:if>
		$("#sumbitbtn").click(function() { 			
			if($("input[name='campaign.range']:checked").val()=="RedGreenCategory"){
				<c:if test="${campaign.type == 'C01'}">
					alert("红绿标分类暂不支援<立折优惠>!");
				    return false;
				</c:if>
				 $("#redRange").formValidator().inputValidator({
						min:1,
						max:1000,
						onerror:"紅標活动目錄须小于1000个字元且为必填"
					});
					
				 $("#greenRange").formValidator().inputValidator({
						min:1,
						max:1000,
						onerror:"綠標活动目錄须小于1000个字元且为必填"
				});
			}
		});
		
		<c:if test="${campaign.range eq 'RedGreenCategory'}">
			<c:if test="${campaign.type eq 'C01'}">
			$(".rgdisable").attr("disabled",true);
			</c:if>
		$(".btndisable").attr("disabled",true);
		$("#buyqry").html("合法购买组(红绿商品各1个为1组)");
		</c:if>
	});	
function opt(type, index) {
	var formObj = document.formObj;
	formObj.operation.value = index;
	if(type=='add') {
		formObj.action = 'addExt.do';
	} else if(type=='del') {
		formObj.action = 'delExt.do';
	} else {
		c
		return false;
	}
	formObj.submit();
	return true;
}
function flashEdit() {
	var formObj = document.formObj;
	formObj.action = 'edit.do';
	formObj.submit();
	return true;
}
</script>
<h1>行销活动管理</h1><div style="color:red">
<s:actionerror />
<s:actionmessage />
<s:fielderror /></div>
<s:form name="formObj" id="formObj" action="save.do" method="post">
<s:hidden name="operation"/>
<input name="uuid" type="hidden" value="${campaign.uuid}"/>
<br />
<table class="tb-data" width="100%">
	<tr>
		<td colspan="2">
			<div class="f-link">
				<input type="submit" value="储存修改">
<c:if test="${!empty campaign.uuid}">
				<input type="button" onclick="document.location='view.do'" value="回检视页">
</c:if><c:if test="${empty campaign.uuid}">
				<input type="button" onclick="document.location='search.do'" value="回活动查询页">
</c:if>
			</div>
		</td>
	</tr>
	<tr>
		<th>* 活动类型</th>
		<td><s:radio list="menuType" id="campaigntype" name="campaign.type" listValue="desc" onchange="flashEdit()"></s:radio>
		</td>
	</tr>
	<tr>
		<th width="20%">* 活动名称<br/>建议25字内,限制45字内</th>
		<td><s:textfield name="campaign.campaignName" id="campaignName" size="40"/></td>
	</tr>
	<tr>
		<th>活动说明<br/>限制400字内</th>
		<td><s:textarea name="campaign.campaignDesc" id="campaignDesc" rows="4" cols="60"/></td>
	</tr>
	<tr>
		<th>活动規則<br/>限制600字内</th>
		<td><s:textarea name="campaign.campaignDetail" id="campaignDetail" rows="4" cols="60"/>
		</td>
	</tr>
	<c:choose>
	<c:when test = "${campaign.type.code == 'M01' || campaign.type.code == 'M02' || campaign.type.code == 'M03' || campaign.type.code == 'M04'}">
	<input type="hidden" value="Order" name="campaign.range"/>
	</c:when>
	<c:otherwise>
	<tr>
		<th>* 活动范围</th>
		<td><s:radio list="menuRange" name="campaign.range"  listValue="desc" onchange="flashEdit()"></s:radio>
		</td>
	</tr>
	</c:otherwise>
	</c:choose>
	<c:if test="${campaign.range == 'RedGreenCategory' && campaign.type.code != 'C01' && campaign.type.code != 'M01' && campaign.type.code != 'M02' && campaign.type.code != 'M03'}">
	<tr>
		<th>* 紅標活动目錄<br/>(填入 categoryId 以 , 區隔)</th>
		<td><s:textarea name="redRange" id="redRange" rows="2" cols="60"/>
		</td>
	</tr>
	<tr>
		<th>* 綠標活动目錄<br/>(填入 categoryId 以 , 區隔)</th>
		<td><s:textarea name="greenRange" id="greenRange" rows="2" cols="60"/>
		</td>
	</tr>
	</c:if>

	<c:if test="${campaign.range eq 'Category'}">
	<tr>
		<th>* 活动目錄<br/>(填入 categoryId 以 , 區隔)</th>
		<td><s:textarea name="rangeExtend" id="rangeExt" rows="2" cols="80"/>
		</td>
	</tr>
</c:if><c:if test="${campaign.range eq 'Product'}">
	<tr>
		<th>* 活动商品<br/>(填入 productId 以 , 區隔)</th>
		<td><s:textarea name="rangeExtend" id="rangeExt" rows="2" cols="80"/>
		</td>
	</tr>
</c:if>

<c:if test="${campaign.type != 'M02' && campaign.type != 'M03' && campaign.type != 'M04'}">	
<tr class="tb-data">
		<th><c:if test="${campaign.type == 'M01'}">发放计算基准<br/>(按订单金额)</c:if><c:if test="${campaign.type != 'M01'}">活动內容</c:if><input type="button" onclick="opt('add', -1);" class="btndisable" value="新增"></th>
		<td>
<table width="100%"><tr class="tb-data">
<c:choose>
<c:when test = "${campaign.type == 'M01'}">
<th>操作</th><th>订单金额范围</th><th>发放规则</th><th>封顶否？</th>
</c:when>
<c:otherwise>
<th>操作</th><th>订单金额</th><th id="buyqry">合法购买量</th><th>活动折减送</th>
</c:otherwise>
</c:choose>
</tr>
<s:iterator value="campaign.typeExtends" var="extend" status="stat">
<tr><td>(<input type="button" onclick="opt('del', ${stat.index});" class="btndisable" value="删除">)</td>
	<td><input name="campaign.typeExtends[${stat.index}].minOrderAmount" class="btndisable" value="${extend.minOrderAmount}" size="10"/> ~ 
		<input name="campaign.typeExtends[${stat.index}].maxOrderAmount" class="btndisable" value="${extend.maxOrderAmount}" size="10"/></td>
	<c:choose>
	<c:when test = "${campaign.type == 'M01'}">
		<td>每<input name="campaign.typeExtends[${stat.index}].minQty" value="${extend.minQty}" size="5"/> 元, 发放 
			<input name="campaign.typeExtends[${stat.index}].maxQty" value="${extend.maxQty}" size="5"/>点积分</td>
		<td><input type="hidden" name="campaign.typeExtends[${stat.index}].campaignTypeExtension" value="M01" size="5" maxlength="10"/>
		<input type="checkbox" id="upperLimit_${stat.index}" <c-rt:if test="${extend.upperLimit}">checked</c-rt:if>/>封顶
		 <span id="span_bonusLimit_${stat.index}"<c-rt:if test="${!extend.upperLimit}"> style="display:none;"</c-rt:if>>(最多得<input id="bonusLimit_${stat.index}" name="campaign.typeExtends[${stat.index}].bonusLimit" value="${extend.bonusLimit}" size="5" maxlength="8">分)</span>
		</td>
	</c:when>
	<c:otherwise>
		<td><input name="campaign.typeExtends[${stat.index}].minQty" class="rgdisable" value="${extend.minQty}" size="5"/> ~ 
			<input name="campaign.typeExtends[${stat.index}].maxQty" class="rgdisable" value="${extend.maxQty}" size="5"/></td>
		<td>${campaign.type.desc}: <input name="campaign.typeExtends[${stat.index}].campaignTypeExtension" class="rgdisable" value="${extend.campaignTypeExtension}" size="5" maxlength="10"/></td>
	</c:otherwise>
	</c:choose>
	</tr>
</s:iterator></table>
		</td>
</tr>
</c:if>
	<c:if test="${campaign.type == 'M04'}">
	<tr>
		<th>* 前三名评价送积分</th>
		<td>
		<input name="campaign.commentFirst3" id="commentFirst3" size="8" value="${campaign.commentFirst3}" maxlength="4">
		</td>
	</tr>
	<tr>
		<th>* 其他评价送积分</th>
		<td>
		<input name="campaign.commentOthers" id="commentOthers" size="8" value="${campaign.commentOthers}" maxlength="4">
		</td>
	</tr>
	</c:if>
	<c:if test="${campaign.type == 'M01' || campaign.type == 'M04'}">
	<tr>
		<th>* 效期开始日</th>
		<td>
		为发放日<input name="campaign.startPeriod" id="startPeriod" size="5" value="${campaign.startPeriod}" maxlength="3">日 后开始可使用
		</td>
	</tr>
	<tr>
		<th>* 效期长度</th>
		<td>
		<input name="campaign.periodDays" id="periodDays" size="5" value="${campaign.periodDays}" maxlength="3">月   「积分效期截止日统一为计算后日期之该月月底日」
		</td>
	</tr>
	</c:if>
	<c:if test="${campaign.type == 'M02'}">
	<tr>
		<th>* 积分折抵比率</th>
		<td>
		积分<input name="campaign.offsetRate" id="offsetRate" size="5" value="${campaign.offsetRate}" maxlength="5"> = 1元
		</td>
	</tr>
	<tr>
		<th>* 积分折抵上限</th>
		<td>
		订单金额<input name="campaign.offsetUpperLimit" id="offsetUpperLimit" size="5" value="${campaign.offsetUpperLimit}" maxlength="2"> %
		</td>
	</tr>
	<tr>
		<th>* 积分折抵金额上限</th>
		<td>
		上限<input name="campaign.offsetDiscountLimit" id="offsetDiscountLimit" size="5" value="${campaign.offsetDiscountLimit}" maxlength="5"> 元
		</td>
	</tr>
	</c:if>
	<c:if test="${campaign.type == 'M03'}">
	<tr>
		<th>* 发送规则</th>
		<td>
		每日登入<input name="campaign.loginCount" id="loginCount" size="5" value="${campaign.loginCount}" maxlength="2">次，发送积分<input name="campaign.giveBonus" id="giveBonus" size="5" value="${campaign.giveBonus}" maxlength="3">点
		</td>
	</tr>
	</c:if>
	<tr>
		<th>* 活动起始日期时间</th>
		<td>
		<input name="startDate" id="startDate" size="10" value="<fmt:formatDate value="${campaign.startDateTime}" pattern="yyyy-MM-dd"/>">
		<input name="startTime" id="startTime" size="8" value="<fmt:formatDate value="${campaign.startDateTime}" pattern="HH:mm"/>">
		</td>
	</tr>
	<tr>
		<th>* 活动结束日期时间</th>
		<td>
		<input name="endDate" id="endDate" size="10" value="<fmt:formatDate value="${campaign.endDateTime}" pattern="yyyy-MM-dd"/>">
		<input name="endTime" id="endTime" size="8" value="<fmt:formatDate value="${campaign.endDateTime}" pattern="HH:mm"/>"></td>
	</tr>
	<c:if test="${campaign.type != 'M01' && campaign.type != 'M02' && campaign.type != 'M03' && campaign.type != 'M04'}">
	<tr>
		<th>网页路径</th>
		<td><s:textfield name="campaign.campaignUrl" id="campaignUrl" size="40"/></td>
	</tr>
	</c:if>
	<tr>
		<th>* 活动渠道</th>
		<td>
		<s:radio list="#{'true':'全部渠道'}" name="ignoreCookie" listKey="key" listValue="value"/><br/><br/>
		<s:radio list="#{'false':'特定渠道'}" name="ignoreCookie" listKey="key" listValue="value"/><br/>
<%--
		<s:radio list="#{'true':'全部渠道','false':'特定渠道'}" name="ignoreCookie" listKey="key" listValue="value"/><br/>
 --%>
		<s:select name="campaign.cookieArray" multiple="true" size="5" list="menuChannel.options" listKey="key" listValue="value.codeName"/></td>
	</tr>		
	<tr>
		<th>* 活動Domain</th>
		<td>
		<s:select name="campaign.domain" list="menuDomain.options" listKey="key" listValue="value.name"/></td>
	</tr>
	<tr>
		<th>* 启用</th>
		<td><s:radio list="#{'true':'是','false':'否'}" name="campaign.enable" listKey="key" listValue="value"></s:radio></td>
	</tr>
	<tr>
		<th>* 预算归属</th>
		<td><s:radio list="menuBudget.options" name="campaign.budget" listValue="value.name"/></td>
	</tr>
	<tr>
		<th>备注</th>
		<td><s:textarea name="campaign.memo" id="campaignMemo" rows="4" cols="60"/></td>
	</tr>
	<tr>
		<th>修改备注</th>
		<td>
建立：<fmt:formatDate value="${campaign.createDate}" pattern="yyyy-MM-dd HH:mm"/> / ${campaign.createUser} <br/>
修改：<fmt:formatDate value="${campaign.modifyDate}" pattern="yyyy-MM-dd HH:mm"/> / ${campaign.modifyUser}
		</td>
	</tr>	
		<tr>
		<td colspan="2">
			<div class="f-link">
				<input type="submit" id="sumbitbtn" value="储存修改">
<c:if test="${!empty campaign.uuid}">
				<input type="button" onclick="document.location='view.do'" value="回检视页">
</c:if><c:if test="${empty campaign.uuid}">
				<input type="button" onclick="document.location='search.do'" value="回活动查询页">
</c:if>
			</div>
		</td>
	</tr>

</table>

</s:form>